<!DOCTYPE html>
<html>
<head>
    <title>系统管理员</title>
    {include file="common/inc_meta" /}
</head>
<body>
 <div id="wrapper">
    {include file="common/inc_menu" /}
       <div id="page-wrapper" class="gray-bg">
          {include file="common/inc_top" /}
            <div class="row wrapper border-bottom white-bg page-heading" style="padding-top:20px;font-weight: normal;">
                <div class="col-sm-4">
                    <h2 style="margin-bottom:10px;">系统管理员</h2>
                    <ol class="breadcrumb">
                        <li><a href="{$admin.index_page}">主页</a></li>
                        <li><a>系统</a></li>
                        <li class="active"><strong>系统管理员</strong></li>
                    </ol>
                </div>
                <div class="col-lg-2"></div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
               <div class="row">
                  <div class="col-lg-12">
                     <div class="ibox float-e-margins">
                        <div class="ibox-content" style="padding: 10px 10px 7px 10px; position: relative;">
                                <form role="form" class="form-inline resettokendiv" onsubmit="return false;">
                                    <div class="form-group">
                                          状态&nbsp;
                                          <select class="form-control" id="vStatus">
                                            <option value="ALL">所有</option>
                                            <option value="1">启用</option>
                                            <option value="0">禁用</option>
                                          </select>
                                    </div>
                                    <div class="form-group" style="margin-left:20px;">
                                          角色&nbsp;
                                          <select class="form-control" id="vGroup">
                                            <option value="ALL">所有</option>
                                            {volist name="group" id="vo"}
                                              <option value="{$vo.id}">{$vo.name}</option>
                                            {/volist}
                                          </select>
                                    </div>
                                    <div class="form-group" style="margin-left:20px;">
                                          门店&nbsp;
                                          <select class="form-control" id="vShop">
                                            <option value="ALL">所有</option>
                                            <option value="0">总后台管理人员</option>
                                            {volist name="shop_list" id="vo"}
                                              <option value="{$vo.id}">{$vo.short_name}</option>
                                            {/volist}
                                          </select>
                                    </div>
                                    <div class="form-group" style="margin-left:20px;">
                                        仓库&nbsp;
                                        <select class="form-control" id="vHouseId" name="vHouseId">
                                          <option value="ALL">所有</option>
                                          {volist name="house_list" id="vo"}
                                          <option value="{$vo.id}">{$vo.name}</option>
                                          {/volist}
                                        </select>
                                    </div>
                                    <div class="form-group" style="margin-left:20px;">
                                        关键词&nbsp;
                                        <input type="text" placeholder="登录账号或姓名" id="inputKeyWord" class="form-control">
                                    </div>
                                    &nbsp;&nbsp;
                                    <button data-toggle="button" class="btn btn-primary btn-outline" type="button" id="queryBtn">重新查询</button>
                                </form>
                                <div style="position: absolute; right:15px;top:13px;">
                                    <button data-toggle="button" class="btn btn-primary btn-sm" type="button" id="addBtn">新增</button>
                                </div>
                        </div>
                        <table class="table table-striped table-bordered table-hover white-bg">
                        <thead>
                            <tr>
                                  <th style="width:5%;text-align:center;">序号</th>
                                  <th>登录账号</th>
                                  <th>真实姓名</th>
                                  <th>性别</th>
                                  <th>角色组</th>
                                  <th>状态</th>
                                  <th>归属门店</th>
                                  <th>归属仓库</th>
                                  <th>创建时间</th>
                                  <th>最后登录</th>
                                  <th style="width:10%;text-align:center;">操作</th>
                            </tr>
                        </thead>
                        <tbody id="ListTable"></tbody>
                        <tfoot>
                            <tr>
                                  <th style="width:5%;text-align:center;">序号</th>
                                  <th>登录账号</th>
                                  <th>真实姓名</th>
                                  <th>性别</th>
                                  <th>角色组</th>
                                  <th>状态</th>
                                  <th>归属门店</th>
                                  <th>归属仓库</th>
                                  <th>创建时间</th>
                                  <th>最后登录</th>
                                  <th style="width:10%;text-align:center;">操作</th>
                            </tr>
                        </tfoot>
                        </table>
                        <div id="pagebox" style="padding:0px 10px 30px 0px;background: #ffffff;height:50px;text-align:right;"></div>
                      </div>
                   </div>
                 </div>


            </div>
     {include file="common/inc_footer" /}
     </div>
 </div>
<!-- Mainly scripts -->
{include file="common/inc_jsfile" /}

<script>
var _p = {$page}, _vstatus = 'ALL', _vgroup = 'ALL', _vshop = 'ALL', _vhouse = 'ALL', _keyword = '';
$(function(){
  //类型绑定
  $("#vStatus").change(function(){
      _vstatus = $(this).val();
      _p = 1;
      getPageData();
  });
  //角色选择绑定
  $("#vGroup").change(function(){
      _vgroup = $(this).val();
      _p = 1;
      getPageData();
  });
  //门店选择绑定
  $("#vShop").change(function(){
      _vshop = $(this).val();
      _p = 1;
      getPageData();
  });
  //仓库选择
  $("#vHouseId").change(function(){
      _vhouse = $(this).val();
     _p = 1;
     getPageData();
  });
  //查询
  $("#queryBtn").click(function(){
     _keyword = $.trim($("#inputKeyWord").val());
     _p = 1;
     getPageData();
  });
  //新增
  $("#addBtn").click(function(){
     window.location.href = "{:url('admin/admin/add')}";
  });
  getPageData();
});
//加载数据
function getPageData(){
 _Admin.ajax("{:url('admin/admin/index')}",{page:_p,vstatus:_vstatus,vgroup:_vgroup,shopid:_vshop,houseid:_vhouse,word:_keyword},function(d){
   if(d.err == '0')
   {
      $('#ListTable').empty();
       $.each(d.list, function(i,v){  
         var _class = (i%2 ==0) ? "gradeA" : "gradeB";
         var _editLink = "{:url('admin/admin/edit')}?id=" + v.id;
         var _editHtml = "<a href=\"" + _editLink + "\" class=\"btn btn-outline btn-primary btn-sm\">修改</a>";
         _editHtml += "&nbsp;&nbsp;&nbsp;<a onClick=\"delAction('" + v.id + "');\" class=\"btn btn-outline btn-warning btn-sm\">删除</a>";
         var html = '<tr class="' + _class + '">\
                <td style="width:5%;text-align:center;">' + parseInt(i+1) + '</td>\
                <td>' + v.admin_name + '</td>\
                <td>' + v.nickname + '</td>\
                <td>' + v.sex + '</td>\
                <td>' + v.group_name + '</td>\
                <td>' + v.status + '</td>\
                <td>' + v.shop_name + '</td>\
                <td>' + v.warehouse_name + '</td>\
                <td>' + v.create_time + '</td>\
                <td>' + v.admin_lg_time + '</td>\
                <td style="width:10%;text-align:center;">' + _editHtml + '</td>\
            </tr>';
         $('#ListTable').append(html);  
      });
      LoadPageBody(d.page, d.limit, d.total);  
   }else{
     _Admin.emptyTabel(d.msg,30,'#ListTable','#pagebox');  
   }
 });  
}
//参数 当前页 / 每页显示数量 / 总记录数
function LoadPageBody(_page = 0, _limit = 0, _count = 0)
{
 Laypage.render({
    elem: 'pagebox'
    ,curr: _page
    ,limit:_limit
    ,count: _count
    ,layout: ['count', 'prev', 'page', 'next', 'skip']
    ,jump: function(obj, first){
      _p = obj.curr;
      if(!first) getPageData();
    }
 });  
}
//删除
function delAction(_id)
{
    layer.confirm('您确定要删除当前的记录？', {
      btn: ['删除','取消']
    }, function(){
        _Admin.ajax("{:url('admin/admin/del')}",{id:_id},function(d){
           layer.closeAll();
           if(d.err == '0')
           {
             layer.msg(d.msg, {time: 2000,anim: 4},function(){window.location.reload();});
           }else{
             layer.msg(d.msg, {time: 2000,anim: 4});
           }
         });
    }, function(){
      layer.closeAll();
    });
}
</script>
</body>
</html>
